/**
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * Copyright (C) 2010 Remon van Vliet
 */
package com.google.code.mochadb.impl;

import java.util.*;

import com.google.code.mochadb.*;

/**
 * 
 * @author Remon van Vliet
 * 
 * @see com.google.code.mochadb.OperationBuilder
 * 
 */
public abstract class OperationBuilderImpl<B, D> implements OperationBuilder<B, D> {

	protected final Map<String, Object> parameters = new HashMap<String, Object>();

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.google.code.mochadb.OperationBuilder#setParameter(int, java.lang.Object)
	 */
	public B setParameter(int index, Object value) {
		parameters.put(Integer.toString(index), value);

		return getThis();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.google.code.mochadb.OperationBuilder#setParameter(java.lang.String, java.lang.Object)
	 */
	public B setParameter(String key, Object value) {
		parameters.put(key, value);

		return getThis();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.google.code.mochadb.OperationBuilder#setParameters(java.util.Map)
	 */
	public B setParameters(Map<String, Object> parameters) {
		parameters.putAll(parameters);

		return getThis();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.google.code.mochadb.OperationBuilder#setParameters(java.lang.Object[])
	 */
	public B setParameters(Object... parameterValues) {

		int index = 1;
		for (Object value : parameterValues) {
			setParameter(index++, value);
		}

		return getThis();
	}

	protected abstract B getThis();

}
